﻿function Ajax(data, callback) {
    $.ajax({
        type: "get",
        url: "../Ajax.ashx?v=" + parseInt(Math.random() * 1000000000),
        data: data,
        async: true,
        timeout: 300000,
        beforeSend: function () {

            $.messager.progress({

                text: '数据执行中...',
            });

        },
        success: function (msg) {
            $.messager.progress('close');
            callback(msg);

        },
        error: function (xhr, type, errorThrown) {
            $.messager.progress('close');

        }
    });
}


function AjaxByPost(data, callback) {

    $.ajax({
        type: "post",
        url: "../uploadImg.ashx",
        data: data,
        async: true,
        timeout: 300000,
        beforeSend: function () {

            $.messager.progress({

                text: '数据执行中...',
            });

        },
        success: function (msg) {
            $.messager.progress('close');
            callback(msg);

        },
        error: function (xhr, type, errorThrown) {

            alert(JSON.stringify(errorThrown));
            $.messager.progress('close');

        }
    });
}

function AlertMessage(Message, Title, ButtonName) {

    if (ButtonName == "") {
        ButtonName = "确定"
    }

    if (Title == "") {
        Title = "提示"
    }

    dd.device.notification.alert({
        message: Message,
        title: Title,//可传空
        buttonName: ButtonName,
        onSuccess: function () {
            //onSuccess将在点击button之后回调
            /*回调*/
        },
        onFail: function (err) { }
    });
}

function AjaxQ(data, callback) {
    $.ajax({
        type: "get",
        url: "../../Ajax.ashx",
        data: data,
        async: true,
        timeout: 300000,
        beforeSend: function () {

            $.messager.progress({

                text: '数据执行中...',
            });

        },
        success: function (msg) {
            $.messager.progress('close');
            callback(msg);

        },
        error: function (xhr, type, errorThrown) {
            $.messager.progress('close');

        }
    });
}

function AjaxQP(data, callback) {

    $.ajax({
        type: "post",
        url: "../Ajax.ashx?v=" + parseInt(Math.random() * 1000000000),
        data: data,
        async: true,
        timeout: 300000,
        beforeSend: function () {

            $.messager.progress({

                text: '数据执行中...',
            });

        },
        success: function (msg) {
            $.messager.progress('close');
            callback(msg);

        },
        error: function (xhr, type, errorThrown) {
            $.messager.progress('close');

        }
    });
}



function getPar(par) {
    //获取当前URL
    var local_url = document.location.href;
    //获取要取得的get参数位置
    var get = local_url.indexOf(par + "=");
    if (get == -1) {
        return false;
    }
    //截取字符串
    var get_par = local_url.slice(par.length + get + 1);
    //判断截取后的字符串是否还有其他get参数
    var nextPar = get_par.indexOf("&");
    if (nextPar != -1) {
        get_par = get_par.slice(0, nextPar);
    }
    return get_par;
}


//去除水平制表符和换行符
function ReplaceChar(str) {
    var s = str.replace(/\t|\n|\v|\r|\f/g, '');
    return s;
}